//
//  ParsefromAPI.m
//  Kiemtragiuaky
//
//  Created by Chau Nguyen DAB on 4/21/15.
//  Copyright (c) 2015 Chau Nguyen DAB. All rights reserved.
//

#import "ParsefromAPI.h"




@implementation ParsefromAPI


+(NSMutableArray *)getDataFromApi{
    
    NSMutableArray* ketqua ;
    
    
    // Tao Url can lay .
    
    NSString* url=@"http://food2fork.com/api/search?key=e8b6c02ca9599f9f1d916a874ddf1db1";
    
    // Tao link .
    
    NSURL* link=[NSURL URLWithString:url] ;
    
    
    // Tao requests
    
    NSURLRequest* request=[NSURLRequest requestWithURL:link];
    NSURLResponse *response ;
    NSError *connectionError;
    
    NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&connectionError];
    
    /*  [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {*/
    
    // Lay du lieu ra Dic.
    
    NSDictionary* dulieu=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    
    ketqua=[dulieu objectForKey:@"recipes"];
    
    //Ghi file

    return ketqua ;
    
}

@end



